<template>
	<view>
		<view style="padding: 20rpx;">
			
			<scroll-view :scroll-top="scrollTop" scroll-y="true"    style="height: 70vh;">
			<view class="box" v-for="item in businessList" :key="item.id"
				style="display: flex; grid-gap: 30rpx; margin-bottom: 10rpx;"  @click="goDetail(item.id,item.isCollect)">
				
				
				<view style="width: 30%;">
					<image :src="item.avatar" style="width: 100%; height: 200rpx; border-radius: 10rpx; display: block;"></image>
				</view>
				
				
				<view style="flex: 1; display: flex; flex-direction: column; justify-content: space-between; grid-gap: 10rpx;">
					
				<view style="font-size: 36rpx; font-weight: bold;">{{ item.name }}</view>
		
					<view style="display: flex;  color: #666; ">
						<view style="flex: 1;">
							<text v-if="item.start !== 'NaN'" style="color: #ff9800; font-weight: bold;">{{item.start}}分</text>
							<text v-if="item.start == 'NaN'" style="color: #ff9800; font-weight: bold;">0.0分</text>
							<text style="margin-left: 10rpx;">已售{{item.count}}</text>
						</view>
						<view style="flex: 1; text-align: right;">30分钟内送达</text>
						</view>
					</view>
					
					<view style="color: #ff9800;">{{item.info}}</view>
					
					<view style="background-color: #ffd281; color: brown; border-radius: 4rpx; width: fit-content;
						padding: 0 8rpx;">{{ item.type || '商家介绍' }}
						
						</view>
						<view class="" @click.stop="cancel(item.id,user.id)">
							<span style="position: relative;left: 160px;top:-25px;height:50px ;" >取消收藏</span>
						</view>
						
						
				 </view>
			
				
				
			</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:uni.getStorageSync('xm-user'),
				collectObj:{},
				businessList:[
					{
					            "id": 18,
					            "username": "张三密码123",
					            "name": "汉堡王1",
					            "password": "$2a$10$ZyHLijAiNstyOYriRhkjiuEkZTTSJmcZiAbKqDoTzs8dOGMIQq2Nu",
					            "role": "BUSINESS",
					            "newPassword": null,
					            "avatar": "http://localhost:9095/files/1699154136252-lADPJwnI4BDhiUbNBQDNA8E_961_1280.jpg",
					            "token": null,
					            "phone": "4599686",
					            "info": "炸鸡汉堡",
					            "address": "南奎大街4号",
					            "license": null,
					            "status": "待审核",
					            "timeRange": "9:00-12:00",
					            "type": "炸鸡汉堡",
					            "start": 4.975,
					            "count": 4,
					            "isCollect": false
					        },
					        {
					            "id": 19,
					            "username": "李四",
					            "name": "蜜雪冰城",
					            "password": "$2a$10$ZyHLijAiNstyOYriRhkjiuEkZTTSJmcZiAbKqDoTzs8dOGMIQq2Nu",
					            "role": "BUSINESS",
					            "newPassword": null,
					            "avatar": "http://localhost:9095/files/1699368206132-lADPJv8gZCKOCmLNBQDNA8E_961_1280.jpg",
					            "token": null,
					            "phone": null,
					            "info": "饮品",
					            "address": "哈尔滨中央广场4号",
					            "license": null,
					            "status": "待审核",
					            "timeRange": null,
					            "type": "饮品",
					            "start": 3.8,
					            "count": 1,
					            "isCollect": true
					        },
					        {
					            "id": 20,
					            "username": "王五",
					            "name": "甜点小屋",
					            "password": "$2a$10$ZyHLijAiNstyOYriRhkjiuEkZTTSJmcZiAbKqDoTzs8dOGMIQq2Nu",
					            "role": "BUSINESS",
					            "newPassword": null,
					            "avatar": "http://localhost:9095/files/1699165131751-lADPJxuMWUjJujnNBQDNA8A_960_1280.jpg",
					            "token": null,
					            "phone": null,
					            "info": "甜点",
					            "address": "甘井子区6路新马路广场",
					            "license": null,
					            "status": "待审核",
					            "timeRange": null,
					            "type": "甜点",
					            "start": "NaN",
					            "count": 0,
					            "isCollect": false
					        }
				]
			}
		},
		onLoad(){
			this.load()
		},
		methods: {
			load(){
				//获取指定userId所收藏的商家
				this.$request.get('/collect/selectcCollectListByUserId/'+this.user.id).then(res =>{
					this.businessList = res.data
				})
				
			},
			cancel(businessId,userId){
				//取消收藏
				this.collectObj.businessId = businessId
				this.collectObj.userId = userId
				
				this.$request.post('/collect/deleteByTwoId',this.collectObj).then(res =>{
					if(res.code == 200){
					uni.showToast({
					  icon: 'success',
					  title: "取消成功~"
					})
					this.load()
					
					}
				})
			},
			goDetail(businessID,isCollect){
				uni.navigateTo({
					url:"/pages/Detail/Detail?businessId="+businessID+"&isCollect="+isCollect
				})
			}
		}
	}
</script>

<style>

</style>
